home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / hypercrd / xcmds / dvlprstc.hqx / Developer Stack 1.3r / card_45653.txt < prev    next >
Text File  |  1991-04-30  |  2KB  |  65 lines

  1. -- card: 45653 from stack: in.3r
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2202
  5. -- name: convertDate
  6.  
  7.  
  8. -- part contents for background part 10
  9. ----- text -----
  10. 15
  11.  
  12. -- part contents for background part 19
  13. ----- text -----
  14. Functions
  15.  
  16. -- part contents for background part 3
  17. ----- text -----
  18. convertDate
  19.  
  20. -- part contents for background part 2
  21. ----- text -----
  22. --This is a general function to convert date formats from
  23. --standard HyperCard format:  m/d/yy    (m or d can have 1 or 2 digits)
  24. --to TPS/IBM format:               yymmdd
  25.  
  26. --Returns "format error" if format is not correct
  27.  
  28. --examples: 
  29. --convertdate(the date)    gives  880528    (if today's date is 5/28/88)
  30. --convertdate("12/1/88")   gives  881201
  31. --convertdate(5/3/88) doesn't work because HyperCard evaluates the 
  32. --expression (2 divisions) before passing the argument to the function.
  33. --however, put the date into Y followed by convertdate(Y) does work
  34. --(apparently HC uses a special hidden marker for dates?)
  35. --From:
  36. --Peter Sylvan
  37. --65 Valley Road 
  38. --Milton, MA 02186
  39. --
  40. --I would like to thank Peter for sending in this contribution to the Developer Stack. [Steve].
  41.  
  42. function convertdate x  -- input format  m/d/yy, output format  yymmdd
  43.   convert x to date   --  adjust date to real calendar if necessary
  44.   if char 3 of x is "/" then  --  two digits in the input m
  45.     put char 1 to 2 of x into mm
  46.     put empty into char 1 to 3 of x
  47.   else if char 2 of x is "/" then  -- only one digit in the input m
  48.     put "0" & char 1 of x into mm
  49.     put empty into char 1 to 2 of x
  50.   else
  51.     return "format error"  -- perhaps should return empty?
  52.   end if
  53.   if char 3 of x is "/" then
  54.     put char 1 to 2 of x into dd
  55.     put empty into char 1 to 3 of x
  56.   else if char 2 of x is "/" then
  57.     put "0" & char 1 of x into dd
  58.     put empty into char 1 to 2 of x
  59.   else
  60.     return "format error"
  61.   end if
  62.   return x & mm & dd
  63. end cdate
  64.  
  65.